<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head><title>SASAPI</title><script src="../../../quicknav.js" type="text/javascript"></script><script><!--
document.quicknavBasePath="../../../index-files";
//--></script><link href="../../../style.css" title="JavaDoc" rel="stylesheet" type="text/css"/><link href="../../../unnatural.css" title="Unnatural" rel="alternate stylesheet" type="text/css"/><link href="../../../overview-summary.html" title="Overview" rel="top"/><meta name="generator" content="http://www.badgers-in-foil.co.uk/projects/as2api/"/></head><body><pre><span class="lineno" id="1">     1  </span><span class="comment doc">/**
<span class="lineno" id="2">     2  </span> * com.sekati.geom.Sort
<span class="lineno" id="3">     3  </span> * @version 1.0.7
<span class="lineno" id="4">     4  </span> * @author jason m horwitz | sekati.com
<span class="lineno" id="5">     5  </span> * Copyright (C) 2007  jason m horwitz, Sekat LLC. All Rights Reserved.
<span class="lineno" id="6">     6  </span> * Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
<span class="lineno" id="7">     7  </span> */</span>
<span class="lineno" id="8">     8  </span>
<span class="lineno" id="9">     9  </span><span class="key">import</span> com.sekati.core.CoreObject;
<span class="lineno" id="10">    10  </span><span class="key">import</span> com.sekati.geom.Point;
<span class="lineno" id="11">    11  </span><span class="key">import</span> com.sekati.math.MathBase;
<span class="lineno" id="12">    12  </span><span class="lineno" id="13">    13  </span><span class="comment doc">/**
<span class="lineno" id="14">    14  </span> * Sort an array of Objects positions into various shapes and patterns.
<span class="lineno" id="15">    15  </span> */</span>
<span class="lineno" id="16">    16  </span><span class="key">class</span> com.sekati.geom.Sort <span class="key">extends</span> CoreObject {
<span class="lineno" id="17">    17  </span><span class="lineno" id="18">    18  </span>	<span class="key">private</span> <span class="key">var</span> _items:Array;
<span class="lineno" id="19">    19  </span>	<span class="key">private</span> <span class="key">var</span> _sort:Array;
<span class="lineno" id="20">    20  </span><span class="lineno" id="21">    21  </span>	<span class="comment doc">/**
<span class="lineno" id="22">    22  </span>	 * Sort Constructor
<span class="lineno" id="23">    23  </span>	 * @param items (Array)
<span class="lineno" id="24">    24  </span>	 * @throws Error on invalid items argument array
<span class="lineno" id="25">    25  </span>	 * {@code Usage:
<span class="lineno" id="26">    26  </span>	 * 	var sort:Sort = new Sort([mc0, mc1, mc2, mc3]);
<span class="lineno" id="27">    27  </span>	 * }
<span class="lineno" id="28">    28  </span>	 */</span>
<span class="lineno" id="29">    29  </span>	<span class="key">public</span> <span class="key">function</span> Sort(items:Array) {
<span class="lineno" id="30">    30  </span>		<span class="comment">// verify that each item in the array has an _x,_y or x,y property to be sorted.</span>
<span class="lineno" id="31">    31  </span>		<span class="key">for</span> (<span class="key">var</span> i:Number = <span class="num_const">0</span>; i &lt; items.length ; i++) {
<span class="lineno" id="32">    32  </span>			<span class="key">if</span>((!items[i]._x &amp;&amp; !items[i]._y) &amp;&amp; (!items[i].x &amp;&amp; !items[i].y)) {
<span class="lineno" id="33">    33  </span>				<span class="key">throw</span> <span class="key">new</span> Error( <span class="str_const">"@@@ "</span> + <span class="key">this</span>.toString( ) + <span class="str_const">" Error: constructor expects 'items' argument array to contain objects with '_x',_y' or 'x','y' properties."</span> );
<span class="lineno" id="34">    34  </span>				<span class="key">return</span>;
<span class="lineno" id="35">    35  </span>			}
<span class="lineno" id="36">    36  </span>		}
<span class="lineno" id="37">    37  </span>		_items = items;
<span class="lineno" id="38">    38  </span>		_sort = <span class="key">new</span> Array( );
<span class="lineno" id="39">    39  </span>	}
<span class="lineno" id="40">    40  </span><span class="lineno" id="41">    41  </span>	<span class="comment doc">/**
<span class="lineno" id="42">    42  </span>	 * Sort items in grid.
<span class="lineno" id="43">    43  </span>	 * @param start (Point)
<span class="lineno" id="44">    44  </span>	 * @param numPerRow (Number)
<span class="lineno" id="45">    45  </span>	 * @param offset (Number)
<span class="lineno" id="46">    46  </span>	 * @return Array
<span class="lineno" id="47">    47  </span>	 * {@code Usage:
<span class="lineno" id="48">    48  </span>	 * 	var positions:Array = new Sort(itemArr).grid(new Point(100,100), 10, 1);
<span class="lineno" id="49">    49  </span>	 * }
<span class="lineno" id="50">    50  </span>	 */</span>	
<span class="lineno" id="51">    51  </span>	<span class="key">public</span> <span class="key">function</span> grid(start:Point, numPerRow:Number, offset:Number):Array {
<span class="lineno" id="52">    52  </span>		<span class="key">var</span> _xpos:Number = <span class="num_const">0</span>;
<span class="lineno" id="53">    53  </span>		<span class="key">var</span> _ypos:Number = <span class="num_const">0</span>;
<span class="lineno" id="54">    54  </span>		<span class="key">var</span> _offset:Number = (!offset) ? <span class="num_const">0</span> : offset;
<span class="lineno" id="55">    55  </span>		
<span class="lineno" id="56">    56  </span>		<span class="comment">// if there is no _width,_height lets assume the items are Points and count them as one pixel.</span>
<span class="lineno" id="57">    57  </span>		<span class="key">var</span> _w:Number = (!_items[<span class="num_const">0</span>]._width) ? <span class="num_const">1</span> : _items[<span class="num_const">0</span>]._width;
<span class="lineno" id="58">    58  </span>		<span class="key">var</span> _h:Number = (!_items[<span class="num_const">0</span>]._height) ? <span class="num_const">1</span> : _items[<span class="num_const">0</span>]._height;
<span class="lineno" id="59">    59  </span>		<span class="key">var</span> _numPerRow:Number = (!numPerRow) ? Math.ceil( (Stage.width - start.x) / (_w + _offset) ) : numPerRow;
<span class="lineno" id="60">    60  </span>		
<span class="lineno" id="61">    61  </span>		<span class="key">for</span> (<span class="key">var</span> i:Number = <span class="num_const">0</span>; i &lt; _items.length ; i++) {
<span class="lineno" id="62">    62  </span>			<span class="key">if</span> ((i % _numPerRow) == <span class="num_const">0</span>) {
<span class="lineno" id="63">    63  </span>				_xpos = _offset;
<span class="lineno" id="64">    64  </span>				_ypos += _h + _offset;
<span class="lineno" id="65">    65  </span>			} <span class="key">else</span> {
<span class="lineno" id="66">    66  </span>				_xpos += _w + _offset;
<span class="lineno" id="67">    67  </span>				_ypos += <span class="num_const">0</span>;
<span class="lineno" id="68">    68  </span>			}
<span class="lineno" id="69">    69  </span>			_sort[i] = <span class="key">new</span> Point( Math.round( _xpos ) + start.x, Math.round( _ypos ) + start.y );
<span class="lineno" id="70">    70  </span>		}
<span class="lineno" id="71">    71  </span>		<span class="key">return</span> _sort;		
<span class="lineno" id="72">    72  </span>	}
<span class="lineno" id="73">    73  </span><span class="lineno" id="74">    74  </span>	<span class="comment doc">/**
<span class="lineno" id="75">    75  </span>	 * Sort items in circle.
<span class="lineno" id="76">    76  </span>	 * @param center (Point)
<span class="lineno" id="77">    77  </span>	 * @param radius (Number)
<span class="lineno" id="78">    78  </span>	 * @return Array
<span class="lineno" id="79">    79  </span>	 * {@code Usage:
<span class="lineno" id="80">    80  </span>	 * 	var positions:Array = new Sort(itemArr).circle(new Point(250,250), 255);
<span class="lineno" id="81">    81  </span>	 * }
<span class="lineno" id="82">    82  </span>	 */</span>
<span class="lineno" id="83">    83  </span>	<span class="key">public</span> <span class="key">function</span> circle(center:Point, radius:Number):Array {
<span class="lineno" id="84">    84  </span>		<span class="key">for</span> (<span class="key">var</span> i:Number = <span class="num_const">0</span>; i &lt; _items.length ; i++) {
<span class="lineno" id="85">    85  </span>			<span class="key">var</span> angle:Number = i * (<span class="num_const">360</span> / _items.length);
<span class="lineno" id="86">    86  </span>			<span class="key">var</span> x:Number = Math.round( (center.x + (radius * Math.cos( (angle - <span class="num_const">180</span>) * Math.PI / <span class="num_const">180</span> ))) );
<span class="lineno" id="87">    87  </span>			<span class="key">var</span> y:Number = Math.round( (center.y + (radius * Math.sin( (angle - <span class="num_const">180</span>) * Math.PI / <span class="num_const">180</span> ))) );
<span class="lineno" id="88">    88  </span>			_sort[i] = <span class="key">new</span> Point( x, y );
<span class="lineno" id="89">    89  </span>		}
<span class="lineno" id="90">    90  </span>		<span class="key">return</span> _sort;
<span class="lineno" id="91">    91  </span>	}
<span class="lineno" id="92">    92  </span><span class="lineno" id="93">    93  </span>	<span class="comment doc">/**
<span class="lineno" id="94">    94  </span>	 * Sort items in sine wave.
<span class="lineno" id="95">    95  </span>	 * @param waves (Number)
<span class="lineno" id="96">    96  </span>	 * @param width (Number) sine wave width
<span class="lineno" id="97">    97  </span>	 * @param width (Number) sine wave y position 
<span class="lineno" id="98">    98  </span>	 * @param widthCap (Number) use max 90% of the width
<span class="lineno" id="99">    99  </span>	 * @param heightCap (Number) use max 60% of the height
<span class="lineno" id="100">   100  </span>	 * @return Array
<span class="lineno" id="101">   101  </span>	 * {@code Usage:
<span class="lineno" id="102">   102  </span>	 * 	var positions:Array = new Sort(itemArr).sine(1.5, Stage.width, Stage.height/2, 0.95, 0.5);
<span class="lineno" id="103">   103  </span>	 * }
<span class="lineno" id="104">   104  </span>	 */</span>
<span class="lineno" id="105">   105  </span>	<span class="key">public</span> <span class="key">function</span> sine(waves:Number, width:Number, yPos:Number, widthCap:Number, heightCap:Number):Array {
<span class="lineno" id="106">   106  </span>		<span class="key">var</span> _degStep:Number = (waves * <span class="num_const">2</span> * Math.PI) / (_items.length - <span class="num_const">1</span>);
<span class="lineno" id="107">   107  </span>		<span class="key">var</span> _xStep:Number = (width * widthCap) / _items.length;
<span class="lineno" id="108">   108  </span>		<span class="key">for</span> (<span class="key">var</span> i:Number = <span class="num_const">0</span>; i &lt; _items.length ; i++) {
<span class="lineno" id="109">   109  </span>			<span class="key">var</span> x:Number = Math.round( (width - width * widthCap) / <span class="num_const">2</span> + _xStep * i );
<span class="lineno" id="110">   110  </span>			<span class="key">var</span> y:Number = Math.round( Math.sin( _degStep * i ) * yPos * heightCap + yPos );
<span class="lineno" id="111">   111  </span>			_sort[i] = <span class="key">new</span> Point( x, y );
<span class="lineno" id="112">   112  </span>		}
<span class="lineno" id="113">   113  </span>		<span class="key">return</span> _sort;
<span class="lineno" id="114">   114  </span>	}
<span class="lineno" id="115">   115  </span><span class="lineno" id="116">   116  </span>	<span class="comment doc">/**
<span class="lineno" id="117">   117  </span>	 * Sort items in triangle.
<span class="lineno" id="118">   118  </span>	 * @param center (Point)
<span class="lineno" id="119">   119  </span>	 * @param sideLength (Number)
<span class="lineno" id="120">   120  </span>	 * @return Array
<span class="lineno" id="121">   121  </span>	 * {@code Usage:
<span class="lineno" id="122">   122  </span>	 * 	var positions:Array = new Sort(itemArr).triangle(new Point(250,250), 500);
<span class="lineno" id="123">   123  </span>	 * }
<span class="lineno" id="124">   124  </span>	 */</span>
<span class="lineno" id="125">   125  </span>	<span class="key">public</span> <span class="key">function</span> triangle(center:Point, sideLength:Number):Array {
<span class="lineno" id="126">   126  </span>		<span class="key">var</span> cY:Number = center.y - (sideLength / <span class="num_const">2</span>);
<span class="lineno" id="127">   127  </span>		<span class="comment">//var perimeter:Number = sideLength*3;</span>
<span class="lineno" id="128">   128  </span>		<span class="key">var</span> objBySide:Number = Math.floor( _items.length / <span class="num_const">3</span> );
<span class="lineno" id="129">   129  </span>		<span class="key">var</span> leftObj:Number = _items.length - objBySide * <span class="num_const">3</span>;
<span class="lineno" id="130">   130  </span>		<span class="key">var</span> posArray:Array = <span class="key">new</span> Array( );
<span class="lineno" id="131">   131  </span>		<span class="key">var</span> radAngle:Number = Math.PI / <span class="num_const">3</span>;
<span class="lineno" id="132">   132  </span>	    
<span class="lineno" id="133">   133  </span>		<span class="key">var</span> spacing:Number;
<span class="lineno" id="134">   134  </span>		<span class="key">for</span> (<span class="key">var</span> i:Number = <span class="num_const">0</span>; i &lt; _items.length ; i++) {
<span class="lineno" id="135">   135  </span>			posArray[i] = <span class="key">new</span> Point( );
<span class="lineno" id="136">   136  </span>			<span class="key">if</span> (i &lt; objBySide) {
<span class="lineno" id="137">   137  </span>				spacing = sideLength / objBySide;
<span class="lineno" id="138">   138  </span>				posArray[i].x = (spacing * i) * Math.cos( radAngle );
<span class="lineno" id="139">   139  </span>				posArray[i].y = (spacing * i) * Math.sin( radAngle );
<span class="lineno" id="140">   140  </span>			}
<span class="lineno" id="141">   141  </span>			<span class="key">if</span> (i &gt;= objBySide &amp;&amp; i &lt; objBySide * <span class="num_const">2</span> + Math.ceil( leftObj / <span class="num_const">2</span> )) {
<span class="lineno" id="142">   142  </span>				spacing = (leftObj != <span class="num_const">0</span>) ? sideLength / (objBySide + <span class="num_const">1</span>) : sideLength / objBySide;
<span class="lineno" id="143">   143  </span>				posArray[i].x = (sideLength * Math.cos( radAngle )) - (spacing * (i - objBySide));
<span class="lineno" id="144">   144  </span>				posArray[i].y = sideLength * Math.sin( radAngle );
<span class="lineno" id="145">   145  </span>			}
<span class="lineno" id="146">   146  </span>			<span class="key">if</span> (i &gt;= objBySide * <span class="num_const">2</span> + Math.ceil( leftObj / <span class="num_const">2</span> )) {
<span class="lineno" id="147">   147  </span>				spacing = (leftObj == <span class="num_const">2</span>) ? sideLength / (objBySide + <span class="num_const">1</span>) : sideLength / objBySide;
<span class="lineno" id="148">   148  </span>				posArray[i].x = -sideLength * Math.cos( radAngle ) + (spacing * (i - (objBySide * <span class="num_const">2</span> + Math.ceil( leftObj / <span class="num_const">2</span> )))) * Math.cos( radAngle );
<span class="lineno" id="149">   149  </span>				posArray[i].y = sideLength * Math.sin( radAngle ) - (spacing * (i - (objBySide * <span class="num_const">2</span> + Math.ceil( leftObj / <span class="num_const">2</span> )))) * Math.sin( radAngle );
<span class="lineno" id="150">   150  </span>			}
<span class="lineno" id="151">   151  </span>			<span class="key">var</span> x:Number = Math.round( center.x + posArray[i].x );
<span class="lineno" id="152">   152  </span>			<span class="key">var</span> y:Number = Math.round( cY + posArray[i].y );
<span class="lineno" id="153">   153  </span>			_sort[i] = <span class="key">new</span> Point( x, y );
<span class="lineno" id="154">   154  </span>		}
<span class="lineno" id="155">   155  </span>		<span class="key">return</span> _sort;
<span class="lineno" id="156">   156  </span>	}
<span class="lineno" id="157">   157  </span><span class="lineno" id="158">   158  </span>	<span class="comment doc">/**
<span class="lineno" id="159">   159  </span>	 * Sort items in flower.
<span class="lineno" id="160">   160  </span>	 * @param center (Point)
<span class="lineno" id="161">   161  </span>	 * @param radius (Number)
<span class="lineno" id="162">   162  </span>	 * @return Array
<span class="lineno" id="163">   163  </span>	 * {@code Usage:
<span class="lineno" id="164">   164  </span>	 * 	var positions:Array = new Sort(itemArr).flower(new Point(250,250), 250);
<span class="lineno" id="165">   165  </span>	 * }
<span class="lineno" id="166">   166  </span>	 */</span>	<span class="lineno" id="167">   167  </span>	<span class="key">public</span> <span class="key">function</span> flower(center:Point, radius:Number):Array {
<span class="lineno" id="168">   168  </span>		<span class="key">var</span> posArray:Array = <span class="key">new</span> Array( );
<span class="lineno" id="169">   169  </span>		<span class="key">var</span> step:Number = (<span class="num_const">2</span> * Math.PI) / _items.length;
<span class="lineno" id="170">   170  </span>		<span class="key">var</span> b:Number = <span class="num_const">1</span>;
<span class="lineno" id="171">   171  </span>		<span class="key">var</span> k:Number = <span class="num_const">2</span>;
<span class="lineno" id="172">   172  </span>		<span class="key">for</span> (<span class="key">var</span> i:Number = <span class="num_const">0</span>; i &lt; _items.length ; i++) {
<span class="lineno" id="173">   173  </span>			<span class="key">var</span> r:Number = b * Math.cos( k * i * step );
<span class="lineno" id="174">   174  </span>			posArray[i] = <span class="key">new</span> Point( );
<span class="lineno" id="175">   175  </span>			posArray[i].x = (r * Math.cos( i * step )) * radius;
<span class="lineno" id="176">   176  </span>			posArray[i].y = (r * Math.sin( i * step )) * radius;
<span class="lineno" id="177">   177  </span>			<span class="key">var</span> x:Number = Math.round( center.x + posArray[i].x );
<span class="lineno" id="178">   178  </span>			<span class="key">var</span> y:Number = Math.round( center.y + posArray[i].y );
<span class="lineno" id="179">   179  </span>			_sort[i] = <span class="key">new</span> Point( x, y );
<span class="lineno" id="180">   180  </span>		}
<span class="lineno" id="181">   181  </span>		<span class="key">return</span> _sort;
<span class="lineno" id="182">   182  </span>	}
<span class="lineno" id="183">   183  </span><span class="lineno" id="184">   184  </span>	<span class="comment doc">/**
<span class="lineno" id="185">   185  </span>	 * Sort items in hedron (star,square,triangle,hexagon,octagon,etc)
<span class="lineno" id="186">   186  </span>	 * @param center (Point)
<span class="lineno" id="187">   187  </span>	 * @param heightCap (Number) use max 90% of the height [default: 0.8]
<span class="lineno" id="188">   188  </span>	 * @param corners (Number)
<span class="lineno" id="189">   189  </span>	 * @param rotate  (Number)
<span class="lineno" id="190">   190  </span>	 * @param isIntraRadial (Boolean) if true star shapes will be drawn else closed hedrons [default: false]
<span class="lineno" id="191">   191  </span>	 * @return Array
<span class="lineno" id="192">   192  </span>	 * {@code Usage:
<span class="lineno" id="193">   193  </span>	 * 	var positions:Array = new Sort(itemArr).hedron(new Point(250,250), 0.6, 8, 90); // create a octagon and rotate 90 degrees.
<span class="lineno" id="194">   194  </span>	 * }
<span class="lineno" id="195">   195  </span>	 */</span>
<span class="lineno" id="196">   196  </span>	<span class="key">public</span> <span class="key">function</span> hedron(center:Point, heightCap:Number, corners:Number, rotate:Number, isIntraRadial:Boolean):Array {
<span class="lineno" id="197">   197  </span>		heightCap = (!heightCap) ? <span class="num_const">0</span>.<span class="num_const">8</span> : heightCap;
<span class="lineno" id="198">   198  </span>		<span class="key">var</span> outerRadius:Number = center.y * heightCap;
<span class="lineno" id="199">   199  </span>		<span class="key">var</span> innerRadius:Number = (!isIntraRadial) ? outerRadius * Math.sqrt( (<span class="num_const">1</span> + Math.cos( (<span class="num_const">2</span> * Math.PI) / corners )) / <span class="num_const">2</span> ) : outerRadius / <span class="num_const">2</span>;
<span class="lineno" id="200">   200  </span>		<span class="key">var</span> cursors:Number = _items.length;
<span class="lineno" id="201">   201  </span>		<span class="key">var</span> lines:Number = corners * <span class="num_const">2</span>;
<span class="lineno" id="202">   202  </span>		<span class="key">var</span> cursorsPerLine:Number = Math.floor( cursors / lines );
<span class="lineno" id="203">   203  </span>		<span class="key">var</span> cursorsLeftOver:Number = cursors - cursorsPerLine * lines; <span class="lineno" id="204">   204  </span>		<span class="comment">// cursors for adoption...</span>
<span class="lineno" id="205">   205  </span>		<span class="key">var</span> alphaStep:Number = (<span class="num_const">2</span> * Math.PI) / corners;
<span class="lineno" id="206">   206  </span>		rotate = (Math.PI / <span class="num_const">180</span>) * rotate;
<span class="lineno" id="207">   207  </span>		<span class="key">var</span> alpha:Number = rotate;
<span class="lineno" id="208">   208  </span>		<span class="key">var</span> actualCursor:Number = <span class="num_const">0</span>;
<span class="lineno" id="209">   209  </span>		<span class="key">var</span> cursorsOnActualLine:Number;
<span class="lineno" id="210">   210  </span>		<span class="key">var</span> xStep:Number;
<span class="lineno" id="211">   211  </span>		<span class="key">var</span> yStep:Number;
<span class="lineno" id="212">   212  </span>		<span class="key">var</span> xAct:Number;
<span class="lineno" id="213">   213  </span>		<span class="key">var</span> yAct:Number;	    
<span class="lineno" id="214">   214  </span>		<span class="key">for</span> (<span class="key">var</span> i:Number = <span class="num_const">0</span>; i &lt; corners ; i++) {
<span class="lineno" id="215">   215  </span>			<span class="key">var</span> xOuter1:Number = Math.sin( alpha ) * outerRadius;
<span class="lineno" id="216">   216  </span>			<span class="key">var</span> yOuter1:Number = Math.cos( alpha ) * outerRadius;
<span class="lineno" id="217">   217  </span>			<span class="key">var</span> xInner:Number = Math.sin( alpha - alphaStep / <span class="num_const">2</span> ) * innerRadius;
<span class="lineno" id="218">   218  </span>			<span class="key">var</span> yInner:Number = Math.cos( alpha - alphaStep / <span class="num_const">2</span> ) * innerRadius;
<span class="lineno" id="219">   219  </span>			<span class="key">var</span> xOuter2:Number = Math.sin( alpha - alphaStep ) * outerRadius;
<span class="lineno" id="220">   220  </span>			<span class="key">var</span> yOuter2:Number = Math.cos( alpha - alphaStep ) * outerRadius;
<span class="lineno" id="221">   221  </span>			<span class="comment">// plot first line</span>
<span class="lineno" id="222">   222  </span>			cursorsOnActualLine = cursorsPerLine;
<span class="lineno" id="223">   223  </span>			<span class="key">if</span> (cursorsLeftOver &gt; <span class="num_const">0</span>) {
<span class="lineno" id="224">   224  </span>				cursorsOnActualLine++; <span class="lineno" id="225">   225  </span>				<span class="comment">// add one of the left over cursors on the line</span>
<span class="lineno" id="226">   226  </span>				cursorsLeftOver--; <span class="comment">// one was adopted!</span>
<span class="lineno" id="227">   227  </span>			}
<span class="lineno" id="228">   228  </span>			xStep = (xInner - xOuter1) / cursorsOnActualLine;
<span class="lineno" id="229">   229  </span>			yStep = (yInner - yOuter1) / cursorsOnActualLine;
<span class="lineno" id="230">   230  </span>			xAct = center.x + xOuter1;
<span class="lineno" id="231">   231  </span>			yAct = center.y + yOuter1;
<span class="lineno" id="232">   232  </span>			<span class="key">for</span> (<span class="key">var</span> j:Number = <span class="num_const">0</span>; j &lt; cursorsOnActualLine ; j++) {
<span class="lineno" id="233">   233  </span>				_sort[actualCursor] = <span class="key">new</span> Point( int( xAct ), int( yAct ) );
<span class="lineno" id="234">   234  </span>				xAct += xStep;
<span class="lineno" id="235">   235  </span>				yAct += yStep;
<span class="lineno" id="236">   236  </span>				actualCursor++;
<span class="lineno" id="237">   237  </span>			}
<span class="lineno" id="238">   238  </span>			<span class="comment">// plot second line</span>
<span class="lineno" id="239">   239  </span>			cursorsOnActualLine = cursorsPerLine;
<span class="lineno" id="240">   240  </span>			<span class="key">if</span> (cursorsLeftOver &gt; <span class="num_const">0</span>) {
<span class="lineno" id="241">   241  </span>				cursorsOnActualLine++; <span class="lineno" id="242">   242  </span>				<span class="comment">// add one of the left over cursors on the line</span>
<span class="lineno" id="243">   243  </span>				cursorsLeftOver--; <span class="comment">// another one was adopted!</span>
<span class="lineno" id="244">   244  </span>			}
<span class="lineno" id="245">   245  </span>			xStep = (xOuter2 - xInner) / cursorsOnActualLine;
<span class="lineno" id="246">   246  </span>			yStep = (yOuter2 - yInner) / cursorsOnActualLine;
<span class="lineno" id="247">   247  </span>			xAct = center.x + xInner;
<span class="lineno" id="248">   248  </span>			yAct = center.y + yInner;
<span class="lineno" id="249">   249  </span>			<span class="key">for</span> (<span class="key">var</span> k:Number = <span class="num_const">0</span>; k &lt; cursorsOnActualLine ; k++) {
<span class="lineno" id="250">   250  </span>				_sort[actualCursor] = <span class="key">new</span> Point( int( xAct ), int( yAct ) );
<span class="lineno" id="251">   251  </span>				xAct += xStep;
<span class="lineno" id="252">   252  </span>				yAct += yStep;
<span class="lineno" id="253">   253  </span>				actualCursor++;
<span class="lineno" id="254">   254  </span>			}
<span class="lineno" id="255">   255  </span>			alpha -= alphaStep;
<span class="lineno" id="256">   256  </span>		}
<span class="lineno" id="257">   257  </span>		<span class="key">return</span> _sort;
<span class="lineno" id="258">   258  </span>	}
<span class="lineno" id="259">   259  </span><span class="lineno" id="260">   260  </span>	<span class="comment doc">/**
<span class="lineno" id="261">   261  </span>	 * Sort items in Star shapes, special {@link com.sekati.geom.Sort.hedon} wrapper.
<span class="lineno" id="262">   262  </span>	 * @param center (Point)
<span class="lineno" id="263">   263  </span>	 * @param heightCap (Number) use max 90% of the height [default: 0.8]
<span class="lineno" id="264">   264  </span>	 * @param corners (Number) of start points
<span class="lineno" id="265">   265  </span>	 * @param rotate (Number)
<span class="lineno" id="266">   266  </span>	 * @return Array
<span class="lineno" id="267">   267  </span>	 * {@code Usage:
<span class="lineno" id="268">   268  </span>	 * 	var positions:Array = new Sort(itemArr).star(new Point(250,250), 0.6, 5, 180);
<span class="lineno" id="269">   269  </span>	 * }
<span class="lineno" id="270">   270  </span>	 */</span>
<span class="lineno" id="271">   271  </span>	<span class="key">public</span> <span class="key">function</span> star(center:Point, heightCap:Number, corners:Number, rotate:Number):Array {
<span class="lineno" id="272">   272  </span>		<span class="key">return</span> hedron( center, heightCap, corners, rotate, <span class="key">true</span> );
<span class="lineno" id="273">   273  </span>	}
<span class="lineno" id="274">   274  </span><span class="lineno" id="275">   275  </span>	<span class="comment doc">/**
<span class="lineno" id="276">   276  </span>	 * Sort items in square, {@link com.sekati.geom.Sort.hedon} wrapper.
<span class="lineno" id="277">   277  </span>	 * @param center (Point)
<span class="lineno" id="278">   278  </span>	 * @param heightCap (Number) use max 90% of the height [default: 0.8]
<span class="lineno" id="279">   279  </span>	 * @return Array
<span class="lineno" id="280">   280  </span>	 * {@code Usage:
<span class="lineno" id="281">   281  </span>	 * 	var positions:Array = new Sort(itemArr).square(new Point(250,250), 0.8);
<span class="lineno" id="282">   282  </span>	 * }
<span class="lineno" id="283">   283  </span>	 */</span>
<span class="lineno" id="284">   284  </span>	<span class="key">public</span> <span class="key">function</span> square(center:Point, heightCap:Number):Array { 
<span class="lineno" id="285">   285  </span>		<span class="key">return</span> hedron( center, heightCap, <span class="num_const">4</span>, <span class="num_const">225</span> ); 
<span class="lineno" id="286">   286  </span>	}
<span class="lineno" id="287">   287  </span><span class="lineno" id="288">   288  </span>	<span class="comment doc">/**
<span class="lineno" id="289">   289  </span>	 * Sort items in hexagon, {@link com.sekati.geom.Sort.hedon} wrapper.
<span class="lineno" id="290">   290  </span>	 * @param center (Point)
<span class="lineno" id="291">   291  </span>	 * @param heightCap (Number) use max 90% of the height [default: 0.8]
<span class="lineno" id="292">   292  </span>	 * @return Array
<span class="lineno" id="293">   293  </span>	 * {@code Usage:
<span class="lineno" id="294">   294  </span>	 * 	var positions:Array = new Sort(itemArr).hexagon(new Point(250,250));
<span class="lineno" id="295">   295  </span>	 * }
<span class="lineno" id="296">   296  </span>	 */</span>
<span class="lineno" id="297">   297  </span>	<span class="key">public</span> <span class="key">function</span> hexagon(center:Point, heightCap:Number):Array { 
<span class="lineno" id="298">   298  </span>		<span class="key">return</span> hedron( center, heightCap, <span class="num_const">6</span>, <span class="num_const">90</span> );
<span class="lineno" id="299">   299  </span>	}
<span class="lineno" id="300">   300  </span><span class="lineno" id="301">   301  </span>	<span class="comment doc">/**
<span class="lineno" id="302">   302  </span>	 * Unsort items in random arrangement.
<span class="lineno" id="303">   303  </span>	 * @param topLeft (Point)
<span class="lineno" id="304">   304  </span>	 * @param bottomLeft (Point)
<span class="lineno" id="305">   305  </span>	 * @return Array
<span class="lineno" id="306">   306  </span>	 * {@code Usage:
<span class="lineno" id="307">   307  </span>	 * 	var positions:Array = new Sort(itemArr).unsort(new Point(0,0), new Point(Stage.width, Stage.height));
<span class="lineno" id="308">   308  </span>	 * }
<span class="lineno" id="309">   309  </span>	 */</span>
<span class="lineno" id="310">   310  </span>	<span class="key">public</span> <span class="key">function</span> unsort(topLeft:Point, bottomRight:Point):Array {
<span class="lineno" id="311">   311  </span>		<span class="key">for</span> (<span class="key">var</span> i:Number = <span class="num_const">0</span>; i &lt; _items.length ; i++) {
<span class="lineno" id="312">   312  </span>			_sort[i] = <span class="key">new</span> Point( MathBase.rnd( topLeft.x, bottomRight.x ), MathBase.rnd( topLeft.y, bottomRight.y ) );
<span class="lineno" id="313">   313  </span>		}
<span class="lineno" id="314">   314  </span>		<span class="key">return</span> _sort;
<span class="lineno" id="315">   315  </span>	}	
<span class="lineno" id="316">   316  </span>}</pre><ul class="main_nav" id="main_nav"><li><a href="../../../overview-summary.html" title="Overview of SASAPI" class="button">Overview</a></li><li><a href="package-summary.html" title="Overview of package com.sekati.geom" class="button">Package</a></li><li><a href="Sort.html" title="Detail of com.sekati.geom.Sort API" class="button">Class</a></li><li><span class="button nav_current">Source</span></li><li><a href="../../../index-files/index.html" title="Alpabetical index of types and members" class="button">Index</a></li></ul><div class="footer"><a href="http://www.badgers-in-foil.co.uk/projects/as2api/" title="ActionScript 2 API Documentation Generator">as2api</a></div></body></html>